import java.util.ArrayList;

public class Leaderboard {
    private ArrayList<PlayerScore> list = new ArrayList<>();

    public void addScore(String name, int score) {
        list.add(new PlayerScore(name, score));
    }

    // 冒泡排序
    public void sort() {
        for (int i = 0; i < list.size(); i++)
            for (int j = 0; j < list.size()-i-1; j++)
                if (list.get(j).score < list.get(j+1).score) {
                    PlayerScore tmp = list.get(j);
                    list.set(j, list.get(j+1));
                    list.set(j+1, tmp);
                }
    }

    public void print() {
        sort();
        System.out.println("排行榜：");
        for (PlayerScore ps : list)
            System.out.println(ps.name + " : " + ps.score);
    }
}